﻿using System.ServiceModel;

namespace GianosNET.Common.ServerUtils
{
    /// <summary>
    /// This class will act as a custom context, an extension to the OperationContext.
    /// This class holds all context information for our application.
    /// </summary>
    public class ServerContext : IExtension<OperationContext>
    {
        private string _userId;        
        private string _token;
        private bool _isAuhtenticated;

        public string UserId
        {
            get
            {
                return _userId;
            }
            set
            {
                _userId = value;
            }
        }

        public string Token
        {
            get
            {
                return _token;
            }
            set
            {
                _token = value;
            }
        }

        public bool IsAuthenticated
        {
            get
            {
                return _isAuhtenticated;
            }
            set
            {
                _isAuhtenticated = value;
            }
        }

        // Get the current one from the extensions that are added to OperationContext.
        public static ServerContext Current
        {
            get 
            { 
                return OperationContext.Current.Extensions.Find<ServerContext>(); 
            }
        } 

        #region IExtension<OperationContext> Members
        public void Attach(OperationContext owner)
        {
        }

        public void Detach(OperationContext owner)
        {
        }
        #endregion
    }
}